/**
 * Copyright (C) 2016 The Ant Open Source Project
 * Created by Administrator  ant  on 2016/8/31  21:55
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.view.cn.activities;

import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;

import com.ant.view.cn.R;
import com.ant.view.cn.base.BaseActivity;
import com.ant.view.cn.utils.AntLog;

public class Demo1001 extends BaseActivity {
    private ScrollView sv;
    private View view;
    private int measureHeight = 0, svHeight = 0,y=0;

    @Override
    public int getLaout() {
        return R.layout.ac_demo1001;
    }

    @Override
    public void initView() {
        sv = (ScrollView) findViewById(R.id.ac_demo1001_sv);
    }

    @Override
    public void initData() {
        // 获得scrollview的子view
        view = sv.getChildAt(0);
        measureHeight = view.getMeasuredHeight();
        svHeight = sv.getHeight();


    }

    @Override
    public void initListener() {
        sv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (MotionEvent.ACTION_MOVE == motionEvent.getAction())
                    svListener();
                return false;
            }

        });

    }

    public void svListener() {
        measureHeight=view.getMeasuredHeight();
        svHeight=sv.getHeight();
        y=sv.getScrollY();
        AntLog.i(TAG, "scrollY=" + y +", svHeight="+svHeight
                +",  mheight="+measureHeight+", all="+(y+svHeight)+
                ", isBottom=" + (measureHeight <= (svHeight + y)));

    }
}
